﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MetroFramework.Forms;
using Managistics.Warehouse.Views.Interfaces;
using Managistics.Model;
using Managistics.Warehouse.Controllers.Interfaces;
using Managistics.Warehouse.Factories;
using Managistics.Model.ValueObject;

namespace Managistics.Warehouse.Views.Purchases
{
    public partial class ViewEnterInputFromPurchase : MetroForm, IViewEnterFromPurchaseView
    {
        public List<PurchaseOrderVO> listPurchaseOrders;
        private PurchaseOrderVO vo;

        public ViewEnterInputFromPurchase()
        {
            this.vo = new PurchaseOrderVO();            
            InitializeComponent();
            InitializeListView();
            base.Closed += delegate { Closed(); };

            InitDataGetPurchaseOrders();
        }

        private void InitializeListView()
        {
            this.listPurchaseOrders = new List<PurchaseOrderVO>();
            gridPurchaseOrder.DataSource = listPurchaseOrders;
            gridPurchaseOrder.SetObjects(listPurchaseOrders);
        }

        public event Action InitDataGetPurchaseOrders = delegate { };
        public new event Action Closed = delegate { };
        public event Action LoadPurchaseOrders = delegate { };

        public void Open()
        {
            ShowDialog();
        }

        public void Open(IView view)
        {
            this.MdiParent = (Form)view;
            this.WindowState = FormWindowState.Maximized;
            this.Dock = DockStyle.Fill;
            this.Show();
            this.BringToFront();
        }

        /*
         * Value Object Model to View
         * 
         */
        public void VOModel2View(PurchaseOrderVO vo)
        {
            this.vo = vo;

            this.gridPurchaseOrder.SetObjects(vo.purchaseOrderList);
            //InitializeGridComponent();
        }

        /*
         * Value Object View to Model
         * 
         */
        public PurchaseOrderVO VOView2Model()
        {
            this.vo.StartDate = metroTextBox1.Text;
            this.vo.EndDate = metroTextBox2.Text;
            this.vo.Id = metroTextBox3.Text;
            this.vo.SupplierId = metroTextBox4.Text;
            this.vo.GoodCode = metroTextBox7.Text;
            this.vo.GoodName = metroTextBox6.Text;
            this.vo.SupplierName = metroTextBox5.Text;
                        
            return this.vo;
        }

        private void NextPage_Click(object sender, EventArgs e)
        {
            this.vo.page_number++;
            LoadPurchaseOrders();
        }

        private void PrevPage_Click(object sender, EventArgs e)
        {
            if (this.vo.page_number > 1)
            {
                this.vo.page_number--;
                LoadPurchaseOrders();
            }
        }

        private void StartPage_Click(object sender, EventArgs e)
        {
            this.vo.page_number = 1;
            LoadPurchaseOrders();           
        }

        private void EndPage_Click(object sender, EventArgs e)
        {
            this.vo.page_number = -1;
            LoadPurchaseOrders();            
        }

        private void Search_Click(object sender, EventArgs e)
        {            
            LoadPurchaseOrders();            
        }
       
    }
}
